Add delorme gpl format.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 21 Dec 2003 09:11:04 +0000 (09:11 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 21 Dec 2003 09:11:04 +0000 (09:11 +0000)
gpsbabel/Makefile
gpsbabel/delgpl.c [new file with mode: 0644]
gpsbabel/vecs.c

index 62944f09049c3b12f3e9e0fc6625a2629b46d07d..b391a4bdbf070aea6a05aef42e7ffe1b868252da 100644 (file)
@@ -18,7 +18,7 @@ FMTS=magproto.o gpx.o geo.o mapsend.o mapsource.o \
        gpsutil.o pcx.o cetus.o copilot.o gpspilot.o magnav.o \
        psp.o holux.o garmin.o tmpro.o tpg.o \
        xcsv.o gcdb.o tiger.o internal_styles.o easygps.o quovadis.o \
-       gpilots.o saroute.o navicache.o psitrex.o geoniche.o
+       gpilots.o saroute.o navicache.o psitrex.o geoniche.o delgpl.o
 
 FILTERS=position.o duplicate.o arcdist.o polygon.o smplrout.o reverse_route.o
 
diff --git a/gpsbabel/delgpl.c b/gpsbabel/delgpl.c
new file mode 100644 (file)
index 0000000..80077f7
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+    DeLorme GPL Track Format.
+
+    Copyright (C) 2003 Robert Lipe, robertlipe@usa.net
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+
+#include <ctype.h>
+#include <time.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "defs.h"
+// #include "magellan.h"
+
+#define MYNAME "GPL"
+
+extern gpsdata_type objective;
+
+typedef struct gpl_point {
+       unsigned int status;
+       unsigned int dummy1;
+       double lat;
+       double lon;
+       double alt; /* in feet */
+       double heading;
+       double speed; /* mps */
+       unsigned int tm;
+       unsigned int dummy3;
+} gpl_point_t;
+
+static FILE *gplfile_in;
+static FILE *gplfile_out;
+
+static void
+gpl_rd_init(const char *fname)
+{
+       gplfile_in = fopen(fname, "rb");
+       if (sizeof(struct gpl_point) != 56) {
+               fatal(MYNAME, ": gpl_point is %d instead of 56.\n", 
+                               sizeof(struct gpl_point));
+       }
+       if (gplfile_in == NULL) {
+               fatal(MYNAME, ": '%s' for reading\n", fname);
+       }
+}
+
+static void
+gpl_read(void)
+{
+       waypoint *wpt_tmp;
+       route_head *track_head;
+       int br;
+       gpl_point_t gp;
+
+       track_head = route_head_alloc();
+       route_add_head(track_head);
+
+       while (!feof(gplfile_in)) {
+               if (0 > fread(&gp, sizeof(gp), 1, gplfile_in)) {
+                       warning(MYNAME, "short data read.\n");
+               }
+               wpt_tmp = xcalloc(sizeof(*wpt_tmp),1);
+               le_read64(&wpt_tmp->latitude, &gp.lat);
+               le_read64(&wpt_tmp->longitude, &gp.lon);
+               le_read64(&wpt_tmp->altitude, &gp.alt);
+               wpt_tmp->creation_time = le_read32(&gp.tm);
+               route_add_wpt(track_head, wpt_tmp);
+       }
+       
+}
+
+
+static void
+gpl_rd_deinit(void)
+{
+       fclose(gplfile_in);
+}
+
+static void
+gpl_wr_init(const char *fname)
+{
+       gplfile_out = fopen(fname, "wb");
+       if (gplfile_out == NULL) {
+               fatal(MYNAME ": Cannot open '%s' for writing\n", fname);
+       }
+}
+
+static void
+gpl_wr_deinit(void)
+{
+       fclose(gplfile_out);
+}
+
+static void
+gpl_trackpt(const waypoint *wpt)
+{
+       gpl_point_t gp = {0};
+
+       le_read64(&gp.lat, &wpt->latitude);
+       le_read64(&gp.lon, &wpt->longitude);
+       le_read64(&gp.alt, &wpt->altitude);
+       le_write32(&gp.tm, wpt->creation_time);
+
+       fwrite(&gp, sizeof(gp), 1, gplfile_out);
+}
+
+static void
+gpl_write(void)
+{
+       route_disp_all(NULL, NULL, gpl_trackpt);
+#if 0
+       /* 
+        * Whitespace is actually legal, but since waypoint name length is
+        * only 8 bytes, we'll conserve them.
+        */
+       setshort_whitespace_ok(mkshort_handle, 0);
+       switch (global_opts.objective)
+       {
+               case trkdata:
+                       mag_track_pr();
+                       break;
+               case wptdata:
+                       waypt_disp_all(mag_waypt_pr);
+                       break;
+               case rtedata:
+                       mag_route_pr();
+                       break;
+               default:
+                       fatal(MYNAME ": Unknown objective.\n");
+       }
+#endif
+}
+
+ff_vecs_t gpl_vecs = {
+       gpl_rd_init,    
+       gpl_wr_init,    
+       gpl_rd_deinit,  
+       gpl_wr_deinit,  
+       gpl_read,
+       gpl_write,
+       NULL
+};
index 108d72f5df1c9ab14b4396a6f27081f7c93fdd79..5f56728b90a66dceb7c631c3af10b84bf0ea3561 100644 (file)
@@ -56,6 +56,7 @@ extern ff_vecs_t saroute_vecs;
 extern ff_vecs_t navicache_vecs;
 extern ff_vecs_t psit_vecs;             /* MRCB */
 extern ff_vecs_t geoniche_vecs;
+extern ff_vecs_t gpl_vecs;
 
 static
 vecs_t vec_list[] = {
@@ -216,6 +217,12 @@ vecs_t vec_list[] = {
                "GeoNiche .pdb",
                NULL
        },
+       {
+               &gpl_vecs,
+               "gpl",
+               "Delorme GPL",
+               NULL
+       },
        {
                NULL,
                NULL,